package com.mtsmda.jpa.eclipseLink.vogella.domain.oneToMany;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "PERSONS_FAMILY")
public class PersonFamily {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID_PERSONS_FAMILY")
	private Integer idPersonFamily;

	@Column(name = "FIRSTNAME_PERSONS_FAMILY", length = 50)
	private String firstname;

	@Column(name = "LASTNAME_PERSONS_FAMILY", length = 50)
	private String lastname;

	@ManyToOne
	private Family family;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Job.class)
	private List<Job> jobs = new ArrayList<>();

	public PersonFamily() {
		super();
	}

	public PersonFamily(String firstname, String lastname) {
		this();
		setFirstname(firstname);
		setLastname(lastname);
	}

	public Integer getIdPersonFamily() {
		return idPersonFamily;
	}

	public void setIdPersonFamily(Integer idPersonFamily) {
		this.idPersonFamily = idPersonFamily;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public Family getFamily() {
		return family;
	}

	public void setFamily(Family family) {
		this.family = family;
	}

	public List<Job> getJobs() {
		return jobs;
	}

	public void setJobs(List<Job> jobs) {
		this.jobs = jobs;
	}

	@Override
	public String toString() {
		return "PersonFamily [idPersonFamily=" + idPersonFamily
				+ ", firstname=" + firstname + ", lastname=" + lastname
				+ ", family=" + family + ", jobs=" + jobs + "]";
	}

}